﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.Users;
using BLL.Users.Impl;
using Model;
using Utils;

namespace BLL.ApplicationConfiguration
{
    /// <summary>
    /// 角色菜单配置类
    /// Author By lijunlin
    /// </summary>
    public class RoleMenuConfiguration
    {
        //存放角色菜单的Map集合
        private static Dictionary<string, Dictionary<string, List<UserMenu>>> roleMenuMap;

        /// <summary>
        /// 初始化
        /// </summary>
        public static void Iniatialization(string path)
        {
            //初始化Map
            roleMenuMap = new Dictionary<string, Dictionary<string, List<UserMenu>>>();


            //WebMaster菜单
            Dictionary<string, List<UserMenu>> webMasterMenu = new Dictionary<string, List<UserMenu>>();

            //-Register Check-
            List<UserMenu> registerCheckList = new List<UserMenu>();
            registerCheckList.Add(new UserMenu("Register List", path + "Security/RegisterCheckList.aspx"));
            webMasterMenu.Add("Register Check", registerCheckList);
            //-Profile-
            List<UserMenu> webMasterProfileList = new List<UserMenu>();
            //webMasterProfileList.Add(new UserMenu("Edit Profile", ""));
            webMasterProfileList.Add(new UserMenu("Change Password", path + "Security/ChangePassword.aspx"));
            webMasterMenu.Add("Profile", webMasterProfileList);

            roleMenuMap.Add("WebMaster", webMasterMenu);

            //Expert菜单
            Dictionary<string, List<UserMenu>> expertMenu = new Dictionary<string, List<UserMenu>>();

            //-Bids-
            List<UserMenu> bidsList = new List<UserMenu>();
            bidsList.Add(new UserMenu("View Bids", path + "Bids/BidsList.aspx?type=allBid"));
            bidsList.Add(new UserMenu("My Bid", path + "Bids/BidsList.aspx?type=myReplyBid"));
            expertMenu.Add("Bids", bidsList);
            //-RFP-
            List<UserMenu> rfpList = new List<UserMenu>();
            rfpList.Add(new UserMenu("Post RFP", path + "RFP/RFPList.aspx?type=postRFP"));
            rfpList.Add(new UserMenu("All RFP", path + "RFP/RFPList.aspx?type=allRFP"));
            rfpList.Add(new UserMenu("My RFP", path + "RFP/RFPList.aspx?type=myRFP"));
            rfpList.Add(new UserMenu("My Virtual Team", path + "VirtualTeam/TeamList.aspx"));
            expertMenu.Add("RFP", rfpList);
            //-EnterpriseAndExpert-
            List<UserMenu> enterpriseAndExpertList = new List<UserMenu>();
            enterpriseAndExpertList.Add(new UserMenu("Enterprise", path + "Enterprise/EnterprisesList.aspx"));
            enterpriseAndExpertList.Add(new UserMenu("Experts", path + "Expert/ExpertsList.aspx"));
            expertMenu.Add("E&E", enterpriseAndExpertList);
            //-Post-
            List<UserMenu> postList = new List<UserMenu>();
            postList.Add(new UserMenu("Post News", path + "News/NewsList.aspx"));
            postList.Add(new UserMenu("Post Event", path + "Events/EventsList.aspx"));
            postList.Add(new UserMenu("Post Publication", path + "Publications/PublicationsList.aspx"));
            postList.Add(new UserMenu("Comment Site", path + "Comment/CommentsList.aspx"));
            expertMenu.Add("Post", postList);
            //-Profile -
            List<UserMenu> expertProfileList = new List<UserMenu>();
            expertProfileList.Add(new UserMenu("Edit Profile", path + "EditProfile/EditProfileExpert.aspx"));
            expertProfileList.Add(new UserMenu("Change Password", path + "Security/ChangePassword.aspx"));
            expertMenu.Add("Profile", expertProfileList);

            roleMenuMap.Add("Expert", expertMenu);

            //Enterprise菜单
            Dictionary<string, List<UserMenu>> enterpriseMenu = new Dictionary<string, List<UserMenu>>();

            //-Bids-
            List<UserMenu> enterpriseBidsList = new List<UserMenu>();
            enterpriseBidsList.Add(new UserMenu("Call For A Bid", path + "Bids/BidsList.aspx?type=callBid"));
            enterpriseBidsList.Add(new UserMenu("My Bid", path + "Bids/BidsList.aspx?type=myBid"));
            enterpriseBidsList.Add(new UserMenu("View Bids", path + "Bids/BidsList.aspx?type=allBid"));
            enterpriseMenu.Add("Bids", enterpriseBidsList);
            //-Post-
            List<UserMenu> enterprisePostList = new List<UserMenu>();
            enterprisePostList.Add(new UserMenu("Comment Site", path + "Comment/CommentsList.aspx"));
            enterpriseMenu.Add("Post", enterprisePostList);
            //-EnterpriseAndExpert-
            List<UserMenu> enterpriseAndExpertList2 = new List<UserMenu>();
            enterpriseAndExpertList2.Add(new UserMenu("Enterprise", path + "Enterprise/EnterprisesList.aspx"));
            enterpriseAndExpertList2.Add(new UserMenu("Experts", path + "Expert/ExpertsList.aspx"));
            enterpriseMenu.Add("E&E", enterpriseAndExpertList2);
            //-Links-
            List<UserMenu> enterpriseLinksList = new List<UserMenu>();
            enterpriseLinksList.Add(new UserMenu("Enterprise Community", ""));
            enterpriseMenu.Add("Links", enterpriseLinksList);
            //-Profile -
            List<UserMenu> enterpriseProfileList = new List<UserMenu>();
            enterpriseProfileList.Add(new UserMenu("Edit Profile", path + "EditProfile/EditProfileEnterprise.aspx"));
            enterpriseProfileList.Add(new UserMenu("Change Password", path + "Security/ChangePassword.aspx"));
            enterpriseMenu.Add("Profile", enterpriseProfileList);

            roleMenuMap.Add("Enterprise", enterpriseMenu);
        }


        /// <summary>
        /// 根据用户编号获取角色菜单
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <returns></returns>
        public static Dictionary<string, List<UserMenu>> GetRoleMenuMap(string userId, string path)
        {
            if (roleMenuMap == null)
            {
                Iniatialization(path);
            }

            //获取用户类型
            string userType = GetUserType(userId);

            return roleMenuMap[userType];
        }


        /// <summary>
        /// 获取用户类型
        /// </summary>
        /// <param name="userId">用户编号</param>
        /// <returns>用户类型</returns>
        private static string GetUserType(string userId)
        {
            UserBO userBO = new UserBOImpl();
            User user = userBO.Find(userId);

            return user.UserType;
        }

    }

}
